package com.betterjr.modules.risk.loan.service;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.betterjr.common.utils.BTAssert;
import com.betterjr.modules.agreement.service.ScfElecAgreementService;
import com.betterjr.modules.risk.loan.dao.LoanProjectSynchInterfaces;
import com.betterjr.modules.risk.loan.data.LoanProjectElcAgreementConstantCollections;
import com.betterjr.modules.risk.loan.entity.LoanProjectRelation;

@Service
public class AccountRegulatoryElcAgreementLoanProjectSynchService implements LoanProjectSynchInterfaces {

    @Autowired
    private ScfElecAgreementService elcAgreementService;

    @Override
    public void InvokeDeleted(LoanProjectRelation anLoan) {

        loggerin.debug(" AccountRegulatoryElcAgreementLoanProjectSynchService  InvokeDeleted " + anLoan);
        try {

            elcAgreementService.saveAndCancelElecLoanAgreement(anLoan.getId(), "12");
        }
        catch (Exception e) {
            BTAssert.notNull(null, "取消账户监管协议出错" + e.getMessage());
        }

    }

    @Override
    public void InvokeEffective(LoanProjectRelation anLoan) {

        loggerin.debug(" AccountRegulatoryElcAgreementLoanProjectSynchService  InvokeEffective " + anLoan);

        try {
            if (anLoan != null && anLoan.getAccountRegulatoryAgreement() != null
                    && LoanProjectElcAgreementConstantCollections.ELCAGREEMENT_SUBTYPE_ONLINE
                            .equals(anLoan.getAccountRegulatoryAgreement().getSubType())
                    && anLoan.getAccountRegulatoryAgreement().getContractTemplateId() != null) {
                elcAgreementService.saveAddElecAgreementByLoanProjectRelation(anLoan,
                        LoanProjectElcAgreementConstantCollections.ELCAGREEMENT_BUSINTYPE_ACCOUNTREGULATORY,
                        Arrays.asList(anLoan.getCustNo()), anLoan.getCustName() + "账户监管电子合同");

            }
        }
        catch (Exception e) {
            BTAssert.notNull(null, "创建账户监管协议出错" + e.getMessage());
        }

    }

}
